package com.goudan.rabbitmq.controller;

import com.goudan.rabbitmq.config.DelayedQueueConfig;
import com.goudan.rabbitmq.util.EventDispatcherUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
public class SendMsgController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送延迟消息，单位：毫秒
     *
     * @param message   消息
     * @param delayTime 延迟时间
     */
    @GetMapping("/sendDelayMsg/{message}/{delayTime}")
    public void sendDelayMsg(@PathVariable String message, @PathVariable Integer delayTime) {
        log.info("当前时间：{},发送一条时长{}毫秒TTL信息给队列QC:{}", new Date(), delayTime, message);
        EventDispatcherUtil.eventDispatch(message, delayTime);
    }
}
